import React from 'react';
import {Table} from "antd";
import ScrollTable from "./component/ScrollTable";

export default () => {

    let dataSource = [{
        id: 1,
        workOrderNo: "2023091312345",
        productSeriesName: "100G LR",
        productCode: "9000123",
        orderTime: 1694622449000,
        inputQuantity: 3000,
        yield: 0.79,
        processYieldList: [{process: "关键工序01 key process 01", yield: 0.95},
            {process: "关键工序02 key process 02", yield: 0.97},
            {process: "关键工序02 key process 03", yield: 0.94}]
    }, {
        id: 2,
        workOrderNo: "2023091312345",
        productSeriesName: "100G LR",
        productCode: "9000123",
        orderTime: 1694622449000,
        inputQuantity: 3000,
        yield: 0.79,
        processYieldList: [{process: "关键工序01 key process 01", yield: 0.91},
            {process: "关键工序02 key process 02", yield: 0.94}]
    }, {
        id: 3,
        workOrderNo: "2023091312345",
        productSeriesName: "100G LR",
        productCode: "9000123",
        orderTime: 1694622449000,
        inputQuantity: 3000,
        yield: 0.79,
        processYieldList: [{process: "关键工序01 key process 01", yield: 0.91},
            {process: "关键工序02 key process 02", yield: 0.94}]
    }, {
        id: 4,
        workOrderNo: "2023091312345",
        productSeriesName: "100G LR",
        productCode: "9000123",
        orderTime: 1694622449000,
        inputQuantity: 3000,
        yield: 0.79,
        processYieldList: [{process: "关键工序01 key process 01", yield: 0.91},
            {process: "关键工序02 key process 02", yield: 0.94}]
    }, {
        id: 5,
        workOrderNo: "2023091312345",
        productSeriesName: "100G LR",
        productCode: "9000123",
        orderTime: 1694622449000,
        inputQuantity: 3000,
        yield: 0.79,
        processYieldList: [{process: "关键工序01 key process 01", yield: 0.91},
            {process: "关键工序02 key process 02", yield: 0.94}]
    }, {
        id: 6,
        workOrderNo: "2023091312345",
        productSeriesName: "100G LR",
        productCode: "9000123",
        orderTime: 1694622449000,
        inputQuantity: 3000,
        yield: 0.79,
        processYieldList: [{process: "关键工序01 key process 01", yield: 0.91},
            {process: "关键工序02 key process 02", yield: 0.94}]
    }, {
        id: 7,
        workOrderNo: "2023091312345",
        productSeriesName: "100G LR",
        productCode: "9000123",
        orderTime: 1694622449000,
        inputQuantity: 3000,
        yield: 0.79,
        processYieldList: [{process: "关键工序01 key process 01", yield: 0.91},
            {process: "关键工序02 key process 02", yield: 0.94}]
    }, {
        id: 8,
        workOrderNo: "2023091312345",
        productSeriesName: "100G LR",
        productCode: "9000123",
        orderTime: 1694622449000,
        inputQuantity: 3000,
        yield: 0.79,
        processYieldList: [{process: "关键工序01 key process 01", yield: 0.91},
            {process: "关键工序02 key process 02", yield: 0.94}]
    }, {
        id: 9,
        workOrderNo: "2023091312345",
        productSeriesName: "100G LR",
        productCode: "9000123",
        orderTime: 1694622449000,
        inputQuantity: 3000,
        yield: 0.79,
        processYieldList: [{process: "关键工序01 key process 01", yield: 0.91},
            {process: "关键工序02 key process 02", yield: 0.94}]
    }, {
        id: 10,
        workOrderNo: "2023091312345",
        productSeriesName: "100G LR",
        productCode: "9000123",
        orderTime: 1694622449000,
        inputQuantity: 3000,
        yield: 0.79,
        processYieldList: [{process: "关键工序01 key process 01", yield: 0.91},
            {process: "关键工序02 key process 02", yield: 0.94}]
    }, {
        id: 11,
        workOrderNo: "2023091312345",
        productSeriesName: "100G LR",
        productCode: "9000123",
        orderTime: 1694622449000,
        inputQuantity: 3000,
        yield: 0.79,
        processYieldList: [{process: "关键工序01 key process 01", yield: 0.91},
            {process: "关键工序02 key process 02", yield: 0.94}]
    }, {
        id: 12,
        workOrderNo: "2023091312345",
        productSeriesName: "100G LR",
        productCode: "9000123",
        orderTime: 1694622449000,
        inputQuantity: 3000,
        yield: 0.79,
        processYieldList: [{process: "关键工序01 key process 01", yield: 0.91},
            {process: "关键工序02 key process 02", yield: 0.94}]
    }, {
        id: 13,
        workOrderNo: "2023091312345",
        productSeriesName: "100G LR",
        productCode: "9000123",
        orderTime: 1694622449000,
        inputQuantity: 3000,
        yield: 0.79,
        processYieldList: [{process: "关键工序01 key process 01", yield: 0.91},
            {process: "关键工序02 key process 02", yield: 0.94}]
    }, {
        id: 14,
        workOrderNo: "2023091312345",
        productSeriesName: "100G LR",
        productCode: "9000123",
        orderTime: 1694622449000,
        inputQuantity: 3000,
        yield: 0.79,
        processYieldList: [{process: "关键工序01 key process 01", yield: 0.91},
            {process: "关键工序02 key process 02", yield: 0.94}, {process: "关键工序01 key process 03", yield: 0.91},
            {process: "关键工序02 key process 04", yield: 0.94}, {process: "关键工序01 key process 05", yield: 0.91},
            {process: "关键工序02 key process 06", yield: 0.94}, {process: "关键工序01 key process 07", yield: 0.91},
            {process: "关键工序02 key process 08", yield: 0.94},
            {process: "关键工序02 key process 09", yield: 0.94},
            {process: "关键工序02 key process 10", yield: 0.94},]
    }, {
        id: 15,
        workOrderNo: "2023091312345",
        productSeriesName: "100G LR",
        productCode: "9000123",
        orderTime: 1694622449000,
        inputQuantity: 3000,
        yield: 0.79,
        processYieldList: [{process: "关键工序01 key process 01", yield: 0.91},
            {process: "关键工序02 key process 02", yield: 0.94}]
    }, {
        id: 16,
        workOrderNo: "2023091312345",
        productSeriesName: "100G LR",
        productCode: "9000123",
        orderTime: 1694622449000,
        inputQuantity: 3000,
        yield: 0.79,
        processYieldList: [{process: "关键工序01 key process 01", yield: 0.91},
            {process: "关键工序02 key process 02", yield: 0.94}]
    }, {
        id: 17,
        workOrderNo: "2023091312345",
        productSeriesName: "100G LR",
        productCode: "9000123",
        orderTime: 1694622449000,
        inputQuantity: 3000,
        yield: 0.79,
        processYieldList: [{process: "关键工序01 key process 01", yield: 0.91},
            {process: "关键工序02 key process 02", yield: 0.94}]
    }, {
        id: 18,
        workOrderNo: "2023091312345",
        productSeriesName: "100G LR",
        productCode: "9000123",
        orderTime: 1694622449000,
        inputQuantity: 3000,
        yield: 0.79,
        processYieldList: [{process: "关键工序01 key process 01", yield: 0.91},
            {process: "关键工序02 key process 02", yield: 0.94}]
    }, {
        id: 19,
        workOrderNo: "2023091312345",
        productSeriesName: "100G LR",
        productCode: "9000123",
        orderTime: 1694622449000,
        inputQuantity: 3000,
        yield: 0.79,
        processYieldList: [{process: "关键工序01 key process 01", yield: 0.91},
            {process: "关键工序02 key process 02", yield: 0.94}]
    }]
    const dp: string[] = [];
    dataSource = dataSource.map(item => {
        let map: any = {};
        item.processYieldList.forEach((w) => {
            map[w.process] = w.yield;
            if (!dp.includes(w.process) && dp.length <= 10) {
                dp.push(w.process)
            }

        })
        return {
            ...item,
            ...map,
        }
    })
    console.log(dp);
    console.log(dataSource);
    const columns = [
        {
            title: 'id',
            key: 'id',
            dataIndex: 'id',
            align: "center",
        },
        {
            title: 'workOrderNo',
            key: 'workOrderNo',
            dataIndex: 'workOrderNo',
            align: "center",
        },
        {
            title: 'productSeriesName',
            key: 'productSeriesName',
            dataIndex: 'productSeriesName',
            align: "center",
        },
        {
            title: 'productCode',
            key: 'productCode',
            dataIndex: 'productCode',
            align: "center",
        },
        {
            title: 'orderTime',
            key: 'orderTime',
            dataIndex: 'orderTime',
            align: "center",
        },
        {
            title: 'inputQuantity',
            key: 'inputQuantity',
            dataIndex: 'inputQuantity',
            align: "center",
        },
        {
            title: 'yield',
            key: 'yield',
            dataIndex: 'yield',
            align: "center",
        },
        {
            title: '实时工序良率 Real-time Process Yield',
            key: 'processYieldList',
            children: dp.map(
                (item) => {
                    return {
                        title: item,
                        dataIndex: item,
                        align: "center",
                    }
                }
            )
        }
    ];
    const getTitle = () => {
        return <></>
    }
    return (
        <>
            <ScrollTable title={getTitle} style={{height: '100%', padding: '10px'}} rowKey={'id'} columns={columns}
                         dataSource={dataSource}/>
        </>
    );
};